home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16627 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: engnews2.Eng.Sun.COM!usenet
  2. From: ball@Eng.Sun.COM (Mike Ball)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: "Pure virtual function called" error
  5. Date: 11 Apr 1996 15:15:28 GMT
  6. Organization: Sun Microsystems Inc.
  7. Message-ID: <4kj7mg$q59@engnews2.Eng.Sun.COM>
  8. References: <Pine.OSF.3.91.960411112749.11275A-100000@bud.cc.swin.edu.au>
  9. Reply-To: ball@Eng.Sun.COM
  10. NNTP-Posting-Host: cygany.eng.sun.com
  11.  
  12. In article 100000@bud.cc.swin.edu.au, John Joseph Newbigin <079519@bud.cc.swin.edu.au> writes:
  13. > On Wed, 10 Apr 1996, Oliver Peck wrote:
  14. > > I am using V4.0.1 of the Sparcworks C++ compiler.
  15. > > 
  16. > > A program is occasionally crashing with the message:-
  17. > > 
  18. > > "****  Pure virtual function called"
  19. > > 
  20. > > Does anyone know what this may mean?
  21. > > 
  22. > If you have a class that inherits another class with a pure virtual 
  23. > function, you MUST write this function for your class because it is only 
  24. > a deffition in the class you are inhereting.  I have never used this but 
  25. > I assume borland C++ would not alow this to compile but I don't know 
  26. > about other compilers.  The compiler may be providing a stub. with this 
  27. > error to alow your program to compile.  To overcome this you will have 
  28. > to write the function for one of the classes(or both).   .....I think:) 
  29. >
  30.  
  31. Well, if I must, I must....
  32.  
  33. This is about 95% nonsense.  It does indeed mean that you are trying to call
  34. a pure function.  You will get this error whether or not you provide a definition
  35. for the function.  The class for which this occurs, being an abstract class,
  36. must be a base class of some entire class which overrides and defines this
  37. virtual function.  If this isn't true, the program won't compile.  During
  38. construction (destruction) of the entire class, the code must ensure that 
  39. when a base class is being constructed (destructed) the polymorphic behavior
  40. of the class is the same as the particular base class being handled.  If one
  41. of these constructors (destructors) calls, directly or indirectly, a pure
  42. virtual function, you will get this message.
  43.  
  44. You can also get the message by calling a virtual function on a deleted class,
  45. as another post points out.  Of course that is undefined behavior, so you
  46. could get ANY message in that situation.  Despite the claim that this is the
  47. most common cause, I've never seen it in real code.  I think it depends on the
  48. programming disciplines being applied.
  49.  
  50. ---
  51. Michael Ball
  52. SunSoft Development Products
  53.  
  54.  
  55.